#include "head.h"
#define FILENAME "1.getopt.c"
#define MAX_SIZE 1024 

int main() {
    int fd;
    char buff[MAX_SIZE] = {0};
    if ((fd = open(FILENAME, O_RDONLY)) < 0) {
        perror("open");
        exit(EXIT_FAILURE);
    }
    size_t rsize = 0;
    if ((rsize = read(fd, buff, MAX_SIZE)) < 0) {
        perror("read");
        exit(EXIT_FAILURE);
    }
    // printf("file read over:\n");
    // printf("%s\n", buff);
    char write_filename[128] = "1.getopt.c.bak";
    if ((fd = open(write_filename, O_RDWR | O_CREAT, 0666)) < 0) {
        perror("open");
        exit(EXIT_FAILURE);
    }
    size_t wsize;
    wsize = write(fd, buff, rsize);
    if (wsize != rsize) {
        fprintf(stderr, "write failed\n");
        exit(EXIT_FAILURE);
    }
    printf("write success\n");


    return 0;
}